package com.appserver.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 为了方便配置，需要登陆的接口统一路径
 *
 *
 */
@RestController
@RequestMapping("/im")
public class IMController {
    private static final Logger LOGGER = LoggerFactory.getLogger(IMController.class);

//    @Autowired
//    private ChatGroupApiService chatGroupApiService;
//
//    @Autowired
//    private ChatGroupCommonService chatGroupCommonService;
//
//    @Autowired
//    private SmallChatGroupCommonService smallChatGroupCommonService;
//
//    @Autowired
//    private IMUserApiService IMUserApiService;
//
//    @Autowired
//    private FansApiService fansApiService;
//
//    @Autowired
//    private GroupQuestionCommonService groupQuestionCommonService;
//
//    //给内部系统鉴权使用，因为目前只有im和activity两个controller需要jwt鉴权，返回用户信息
//    @RequestMapping(path = "/user/auth", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<User> authUser(@RequestParam(value = "userId", defaultValue = "") int userId,
//                                  @RequestParam(value = "needUpdate", defaultValue = "false") Boolean needUpdate) {
//        return new ReturnT<>(IMUserApiService.getUserAndUpdate(userId, needUpdate));
//    }
//
//    @RequestMapping(path = "/chatGroup/searchChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String searchChatGroup(@RequestParam(value = "word", defaultValue = "") String word,
//                                  @RequestParam(value = "userId", defaultValue = "") Integer userId,
//                                  @RequestParam(value = "groupType", defaultValue = "") Integer groupType,
//                                  @RequestParam(value = "groupPage", defaultValue = "") Integer groupPage,
//                                  @RequestParam(value = "groupCount", defaultValue = "") Integer groupCount) {
//        return chatGroupCommonService.searchGroup(word, userId, groupType, groupPage, groupCount);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/createChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String createChatGroup(@RequestParam(value = "name", defaultValue = "") String name,
//                                  @RequestParam(value = "userId", defaultValue = "") int userId,
//                                  @RequestParam(value = "users", defaultValue = "") String users,
//                                  @RequestParam(value = "desc", defaultValue = "") String desc,
//                                  @RequestParam(value = "type", defaultValue = "6") Integer type,
//                                  @RequestParam(value = "user_level", defaultValue = "0") Integer user_level,
//                                  @RequestParam(value = "logo", defaultValue = "") String logo) {
//        return chatGroupApiService.createChatGroup(name, userId, users, desc, type, user_level, logo);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/updateChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String updateChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                  @RequestParam(value = "name", defaultValue = "") String name,
//                                  @RequestParam(value = "userId", defaultValue = "") int userId,
//                                  @RequestParam(value = "desc", defaultValue = "") String desc,
//                                  @RequestParam(value = "logo", defaultValue = "") String logo,
//                                  @RequestParam(value = "user_level", defaultValue = "") Integer user_level,
//                                  @RequestParam(value = "authRule", defaultValue = "") Integer authRule) {
//        return chatGroupApiService.updateChatGroup(chatGroupId, name, userId, desc, logo, user_level, authRule);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/shieldChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String updateChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                  @RequestParam(value = "userId", defaultValue = "") int userId,
//                                  @RequestParam(value = "shieldUserId", defaultValue = "") int shieldUserId,
//                                  @RequestParam(value = "shieldTime", defaultValue = "0") Integer shieldTime) {
//        return chatGroupApiService.shieldChatGroup(chatGroupId, userId, shieldUserId, shieldTime);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/noDisturbChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String updateChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                  @RequestParam(value = "userId", defaultValue = "") int userId
//    ) {
//        return chatGroupApiService.noDisturbChatGroup(chatGroupId, userId);
//    }
//
//    /**
//     *
//     * @param chatGroupId
//     * @param userId 我的id
//     * @return
//     */
//
//    @RequestMapping(path = "/chatGroup/getChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") Integer chatGroupId,
//                               @RequestParam(value = "userId", defaultValue = "") Integer userId) {
//        return chatGroupApiService.getChatGroup(chatGroupId, userId);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/getSmallChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getSmallChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") Integer chatGroupId,
//                               @RequestParam(value = "userId", defaultValue = "") Integer userId) {
//        return smallChatGroupCommonService.getChatGroup(chatGroupId, userId);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/getChatGroupList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getChatGroupList(@RequestParam(value = "userId", defaultValue = "") Integer userId,
//                                   @RequestParam(value = "groupType", defaultValue = "") Integer groupType,
//                                   @RequestParam(value = "groupPage", defaultValue = "") Integer groupPage,
//                                   @RequestParam(value = "groupCount", defaultValue = "") Integer groupCount) {
//        return chatGroupApiService.getChatGroupList(userId, groupType, groupPage, groupCount);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/getChatGroupByCreateUid", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getChatGroupByCreateUid(@RequestParam(value = "userId", defaultValue = "") int userId) {
//        return chatGroupApiService.getChatGroupByCreateUid(userId);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/getChatGroupByUid", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getChatGroupByUid(@RequestParam(value = "userId", defaultValue = "") int userId) {
//        return chatGroupApiService.getChatGroupByUid(userId);
//    }
//
//
//
//    @RequestMapping(path = "/chatGroup/leaveChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String leaveChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                 @RequestParam(value = "userId", defaultValue = "") int userId) {
//        return chatGroupApiService.leaveChatGroup(chatGroupId, userId);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/leaveSmallChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String leaveSmallChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                 @RequestParam(value = "userId", defaultValue = "") int userId) {
//        return smallChatGroupCommonService.leaveSmallChatGroup(chatGroupId, userId);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/dissolveChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String dissolveChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                    @RequestParam(value = "userId", defaultValue = "") int userId
//    ) {
//        return chatGroupApiService.dissolveChatGroup(chatGroupId, userId);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/kickOutChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String leaveChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                 @RequestParam(value = "userId", defaultValue = "") int userId,
//                                 @RequestParam(value = "kickWho", defaultValue = "") String kickWho) {
//        return chatGroupApiService.kickOutChatGroup(chatGroupId, userId, kickWho);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/getChatGroupMember", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getChatGroupMember(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                     @RequestParam(value = "userId", defaultValue = "") int userId) {
//        return chatGroupApiService.getChatGroupMember(chatGroupId, userId);
//    }
//
//
//    @RequestMapping(path = "/chatGroup/joinChatGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String joinChatGroup(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                @RequestParam(value = "userId", defaultValue = "") int userId,
//                                @RequestParam(value = "questionId", defaultValue = "") int questionId,
//                                @RequestParam(value = "reqMsg", defaultValue = "") String reqMsg) {
//        return chatGroupApiService.joinChatGroup(chatGroupId, userId, questionId, reqMsg);
//    }
//
//
//    @RequestMapping(path = "/user/getUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getUser(@RequestParam(value = "userId", defaultValue = "") int userId,
//                          @RequestParam(value = "needUpdate", defaultValue = "true") Boolean needUpdate) {
//        return IMUserApiService.getUserStrAndUpdate(userId, needUpdate);
//    }
//
//
//    @RequestMapping(path = "/user/getUsers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getUser(@RequestParam(value = "userIds", defaultValue = "") String userIds,
//                          @RequestParam(value = "needUpdate", defaultValue = "true") Boolean needUpdate) {
//        return IMUserApiService.getUsersStrAndUpdate(userIds, needUpdate);
//    }
//
//
//    @RequestMapping(path = "/user/getMyTempRelation", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getMyTempRelation(@RequestParam(value = "userId", defaultValue = "") int userId) {
//        return IMUserApiService.getMyTempRelation(userId);
//    }
//
//
//    @RequestMapping(path = "/user/addFriends", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String addFriends(@RequestParam(value = "userId", defaultValue = "") int userId,
//                             @RequestParam(value = "friendsId", defaultValue = "") int friendsId,
//                             @RequestParam(value = "requestMsg", defaultValue = "") String requestMsg) {
//        return IMUserApiService.addFriends(userId, friendsId, requestMsg);
//    }
//
//
//    @RequestMapping(path = "/user/deleteFriends", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String deleteFriends(@RequestParam(value = "userId", defaultValue = "") int userId,
//                                @RequestParam(value = "friendsId", defaultValue = "") int friendsId) {
//        return IMUserApiService.deleteFriends(userId, friendsId);
//    }
//
//
//    @RequestMapping(path = "/user/dealWithTodo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String dealWithTodo(@RequestParam(value = "userId", defaultValue = "") int userId,
//                               @RequestParam(value = "todoId", defaultValue = "") int todoId,
//                               @RequestParam(value = "argeeOrNot", defaultValue = "") boolean argeeOrNot) {
//        return IMUserApiService.dealWithTodo(userId, todoId, argeeOrNot);
//    }
//
//
//    @RequestMapping(path = "/user/shieldUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String shieldUser(@RequestParam(value = "userId", defaultValue = "") int userId,
//                             @RequestParam(value = "toId", defaultValue = "") int toId) {
//        return IMUserApiService.shieldUser(userId, toId);
//    }
//
//
//    @RequestMapping(path = "/user/remarkUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String remarkUser(@RequestParam(value = "userId", defaultValue = "") int userId,
//                             @RequestParam(value = "toId", defaultValue = "") int toId,
//                             @RequestParam(value = "remark", defaultValue = "") String remark) {
//        return IMUserApiService.remarkUser(userId, toId, remark);
//    }
//
//
//    @RequestMapping(path = "/user/iplist", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String iplist() {
//        return IMUserApiService.iplist();
//    }
//
//
//    @RequestMapping(path = "/user/getRecommendUsers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<List<UserVO>> getRecommendUsers(@RequestParam(value = "userId", defaultValue = "") int userId) {
//        return IMUserApiService.getRecommendUsers(userId);
//    }
//
//
//    @RequestMapping(path = "/user/getRelateUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getRelateUser(@RequestParam(value = "userId", defaultValue = "") int userId) {
//        return IMUserApiService.getRelateUserJson(userId);
//    }
//
//
//
//    @RequestMapping(path = "/user/fans", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getFansList(@RequestParam(value = "userId", defaultValue = "") Integer userId, @RequestParam(value = "fansId", defaultValue = "") Integer fansId){
//        return fansApiService.getFansList(userId, fansId);
//    }
//
//
//    @RequestMapping(path = "/user/fans", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<FansVO> addFans(@RequestBody FansVO fansVO){
//        return fansApiService.addFans(fansVO);
//    }
//
//
//
//    @RequestMapping(path = "/user/fansCount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ResponseStatus(HttpStatus.OK)
//    public ReturnT<FansCount> getFansCount(@RequestParam(value = "userId", defaultValue = "") Integer userId){
//        return fansApiService.getFansCount(userId);
//    }
//
//
//
//
//    @RequestMapping(path = "/user/isFriend", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<Boolean> isFriend(@RequestParam(value = "userId", defaultValue = "") int userId,
//                                     @RequestParam(value = "myId", defaultValue = "") Integer myId){
//        Boolean isFriend = IMUserApiService.isFriend(userId, myId).getData();
//        return new ReturnT<>(isFriend);
//
//    }
//
//
//    @RequestMapping(path = "/user/isShield", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<Boolean> isShield(@RequestParam(value = "userId", defaultValue = "") int userId,
//                                     @RequestParam(value = "myId", defaultValue = "") Integer myId){
//        Boolean isShield = IMUserApiService.isShield(userId, myId).getData();
//        return new ReturnT<>(isShield);
//
//    }
//
//
//    @RequestMapping(path = "/user/getRemarkName", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<String> getRemarkName(@RequestParam(value = "userId", defaultValue = "") int userId,
//                                         @RequestParam(value = "myId", defaultValue = "") Integer myId){
//        String remarkName = IMUserApiService.getRemarkName(userId, myId).getData();
//        return new ReturnT<>(remarkName);
//
//    }
//
//
//    @RequestMapping(path = "/chatGroup/getSmallChatGroupMember", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String getSmallChatGroupMember(@RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId,
//                                     @RequestParam(value = "userId", defaultValue = "") int userId) {
//        return smallChatGroupCommonService.getChatGroupMember(chatGroupId, userId);
//    }
//
//
//
//
//    @RequestMapping(path = "/question/createQuestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<GroupQuestion> createQuestion(@RequestBody GroupQuestionBean groupQuestionBean) {
//        return groupQuestionCommonService.createQuestion(groupQuestionBean);
//    }
//
//
//    @RequestMapping(path = "/question/markQuestion", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<String> markQuestion(@RequestHeader(value = "appId", required = false) Integer appId
//            , @RequestParam(value = "id") Integer id, @RequestParam(value = "mark") Integer mark) {
//        return groupQuestionCommonService.markQuestion(id, appId, mark);
//    }
//
//
//    @RequestMapping(path = "/question/{id:\\d+}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<String> deleteQuestion(@PathVariable("id") Long id, @RequestHeader(value = "appId", required = false) Integer appId
//            ) {
//        return groupQuestionCommonService.deleteQuestion(id, appId);
//    }
//
//
//    @RequestMapping(path = "/question/{id:\\d+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<GroupQuestion> getQuestion(@PathVariable("id") Long id, @RequestHeader(value = "appId", required = false) Integer appId
//            ) {
//        return groupQuestionCommonService.getQuestion(id, appId);
//    }
//
//
//    @RequestMapping(path = "/question/getGroupTopQuestion", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<GroupQuestion> getGroupTopQuestion(@RequestHeader(value = "appId", required = false) Integer appId, @RequestParam(value = "chatGroupId", defaultValue = "") int chatGroupId
//    ) {
//        return groupQuestionCommonService.getGroupTopQuestion(chatGroupId, appId);
//    }

}
